<template>

  <div
    style="width:100%;height:240px;"
    id="pie"
  ></div>

</template>

<script>
import echarts from "echarts";

export default {
  name: "dataSourcePie",
  props: {
    PieDataSource: {
      type: Object,
      default: function() {
        return { confirm: 1, unconfirm: 1 };
      }
    }
  },
  data() {
    return {
     
    };
  },
  watch: {
    PieDataSource(curVal, oldVal) {
     
      this.initEchats();
    }
  },
  mounted() {},
  methods: {
    initEchats() {
      var PieDataSource = echarts.init(document.getElementById("pie"));
      let option = {
        color: ["#ffd800", "#f67504"],
        tooltip: {
          trigger: "item",
          formatter: "{a} <br/>{b}: {c} ({d}%)"
        },
        legend: {
          orient: "vertical",
          x: "right",
          data: ['已确认', '未确认']
        },
        series: [
          {
            name: "告警处理",
            type: "pie",
            radius: ["50%", "70%"],
            avoidLabelOverlap: false,
            label: {
              normal: {
                show: false,
                position: "center"
              },
              emphasis: {
                show: true,
                textStyle: {
                  fontSize: "30",
                  fontWeight: "bold"
                }
              }
            },
            labelLine: {
              normal: {
                show: true
              }
            },
            data: [
              {
                value: this.PieDataSource.confirm,
                name: "已确认"
              },
              {
                value: this.PieDataSource.unconfirm,
                name: "未确认"
              }
            ]
          }
        ]
      };

      PieDataSource.setOption(option);
      window.addEventListener("resize", function() {
        PieDataSource.resize();
      });
    }
  }
};
</script>
